'''
Created on Jul 17, 2011

@author: vakumar
'''
from cmd import Cmd
from tower_of_hanoi import play_toh

class Toh_Console(Cmd):
    game = play_toh()
    #d = game.getdict()
    
    prompt = 'ToH:$>'
    
    def do_new(self, num):
        if not num:
            num = 0
        else:
            num = int(num)
        self.game.new(num)
        
    
    def do_reset(self, line):
        self.game.reset()
        
    def do_move(self, line):
        d = self.game.d
        if ' ' in line:
            s, t = line.split()
        else: 
            print 'Wrong I/p'
            return
        try:
            self.game.makemove(d[s], d[t])
        except KeyError as ke:
            print '%s is not valid Tower. Only 1/2/3 is valid value...' %ke
    
    def complete_move(self, text, line, begidx, endidx):
        psbl_mvs = ['1 3', '1 2', '2 3',
                    '2 1', '3 1', '3 2']
        if not text:
            return psbl_mvs
        else:
            res = [x for x in psbl_mvs if x.startswith(text)]
            return res
  
    
    def do_EOF(self, line):
        print 'Good Bye!'
        return True
            
        



if __name__ == '__main__':
    tc = Toh_Console()
    tc.cmdloop()